package com.thunder.rebot.rebotclient.utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

import com.thunder.rebot.rebotclient.R;
import com.thunder.rebot.rebotclient.view.CustomDialog;

public  class DialogUtils {

    public static void showAlertDialog(final Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_alertdialog_layout, null);// 自定义布局
        final CustomDialog dialog = new CustomDialog(context, R.layout.item_alertdialog_layout, 0);
        Button btnQuXiao = (Button) view.findViewById(R.id.btn_alertdialog_quxiao);
        final EditText taskFrom = (EditText) view.findViewById(R.id.et_alertdialog_task1);
        final EditText taskTo = (EditText) view.findViewById(R.id.et_alertdialog_task2);
//        etCompany.setFocusable(false);//设置第一个edittext不可手动输入内容(即不可获取焦点),必须从右侧的下拉列表中选取 //配置下拉列表
        Spinner spfrom = (Spinner) view.findViewById(R.id.iv_alertdialog_location1);
        Spinner spto = (Spinner) view.findViewById(R.id.iv_alertdialog_location2);

        ArrayAdapter<CharSequence> adapterfrom = ArrayAdapter.createFromResource(context, R.array.locations, android.R.layout.simple_spinner_item);
        adapterfrom.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spfrom.setAdapter(adapterfrom);  //为下拉列表设置监听
        spfrom.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                String company = context.getResources().getStringArray(R.array.locations)[arg2];//获取选择的item内容
                taskFrom.setText(company);//将下拉列表中选择的item内容填充到前面的edittext中
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub
            }
        });

        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(context, R.array.locations, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spto.setAdapter(adapter);  //为下拉列表设置监听
        spto.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                String company = context.getResources().getStringArray(R.array.locations)[arg2];//获取选择的item内容
                taskTo.setText(company);//将下拉列表中选择的item内容填充到前面的edittext中
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub
            }
        });
        dialog.setTitle("sss");
//        dialog.create();
        dialog.show();

    }

}
